﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using IBupro.Classes;
using IBupro.Controllers.Classes;

namespace IBupro.Controllers
{
    /// <summary>
    /// Provides action <see cref="Index"/> that renders given html file.
    /// </summary>
    public class StaticHtmlController : CustomController
    {
        public ActionResult Index(string url)
        {
            var filename = string.Format("{0}.{1}.html", url, "cs");
            var path = Path.Combine(Server.MapPath("~/Content/HtmlPages"), filename);
            if (System.IO.File.Exists(path) == false)
            {
                this.FlashMessenger.AddMessage("Html page " + filename + " was not found. Maybe wrong path: " + path, MessageType.Error);
                return RedirectToAction("Index", "Home");
            }

            // We cast it to object in order to invoke correct override
            return this.View((object)System.IO.File.ReadAllText(path));
        }
    }
}
